package com.zqweb.gulimall.essearch.controller;

import com.zqweb.gulimall.essearch.service.MallSearchService;
import com.zqweb.gulimall.essearch.vo.SearchParam;
import com.zqweb.gulimall.essearch.vo.SearchResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
public class SearchController {
    @Autowired
    private MallSearchService mallSearchService;

    @GetMapping("/list.html")
    public String toListHtml(SearchParam searchParam, Model model, HttpServletRequest request){
// 将首页查询商品时携带的检索参数封装成1个公用实体类，然后进行条件查询，从ES服务器中获取到相应的查询结果，然后渲染给搜索页
        // 对于封装不了的属性（条件查询部分对应的路径），自行赋值封装
        String _queryString = request.getQueryString();
        searchParam.set_queryString(_queryString);
        SearchResult res = mallSearchService.searchByParams(searchParam);


        // 设置响应数据，传给list.html界面
        model.addAttribute("result",res);
        return "list";
    }


}
